#

| Chapter 30 vi Tips and Tricks |

## 30.16 Counting Occurrences; Stopping Search Wraps

Want to see how many times you used the word very in a file? There are a couple of easy ways.

First, tell vi to stop searching when you get to the end of the file. Type the command `:set nowrapscan` or put it in your .exrc file (4.9).

1. Move to the top of the file with the `1G` command. Search for the first very with the command `/very` (HINT: using the word-limiting regular expression `/\<very\>` (26.4) instead will keep you from matching words like every). To find the next very, type the `n` (next) command.

   When vi says `Address` `search` `hit` `BOTTOM` `without` `matching` `pattern`, you've found all of the words.

2. Use the command:

   >     :g/very/p

   The matching lines will scroll down your screen.

To find the line numbers, too, type `:set` `number` before your searches.

- JP

30.15 Useful Global Commands (with Pattern Matches) |  | 30.17 Capitalizing Every Word on a Line